const categoriesModel = require("../models/categories_model")
const Result = require("../beans/result")
const mongoUtil = require("../models/mongo_util")


function getNewbeeCategories(callback) {
    categoriesModel.getCategories((err, data) => {
        if (err) {
            callback(new Result(err, null, "分类数据获取失败", 401))
        } else {

            callback(new Result(null, data, "分类数据获取成功", 200))


        }
    })

}

function getCategoriesGoods(callback) {
    categoriesModel.getGoods((err, data) => {
        if (err) {
            callback(new Result(err, null, "分类商品数据获取失败", 401))
        } else {

            callback(new Result(null, data, "分类商品数据获取成功", 200))


        }
    })

}
function AddCategorieslist(Categories, callback) {
    categoriesModel.addCategories(Categories, (err, data) => {
        if (err) {
            callback(new Result(err, null, "添加分类失败", 401))
        } else {
            callback(new Result(null, data, "添加分类成功", 200))
        }
    })
}
function putCategorieslist(putCategories, callback) {
    categoriesModel.updateCategories(putCategories, (err, data) => {
        if (err) {
            callback(new Result(err, null, "修改新商品失败", 401))
        } else {
            callback(new Result(null, data, "修改新商品成功", 200))
        }
    })
}

function deleteCategorieslist(categoryId, callback) {
    categoriesModel.deleteCategories(categoryId, (err, data) => {
        if (err) {
            callback(new Result(err, null, "删除分类失败", 401))
        } else {
            callback(new Result(null, data, "删除分类成功", 200))
        }
    })
}


// 添加二级分类
function AddsecondCategorieslist(secondCategories, callback) {
    categoriesModel.addsecondCategories(secondCategories, (err, data) => {
        if (err) {
            callback(new Result(err, null, "添加二级分类失败", 401))
        } else {
            callback(new Result(null, data, "添加二级分类成功", 200))
        }
    })
}

function putsecondCategorieslist(putsecondCategories, callback) {
    categoriesModel.updatesecondCategories(putsecondCategories, (err, data) => {
        if (err) {
            callback(new Result(err, null, "修改二级分类失败", 401))
        } else {
            callback(new Result(null, data, "修改二级分类成功", 200))
        }
    })
}

function deletesecondCategorieslist(secondCategoriesId, callback) {
    categoriesModel.deletesecondCategories(secondCategoriesId, (err, data) => {
        if (err) {
            callback(new Result(err, null, "删除二级分类失败", 401))
        } else {
            callback(new Result(null, data, "删除二级分类成功", 200))
        }
    })
}
module.exports = {
    getNewbeeCategories,
    getCategoriesGoods,
    AddCategorieslist,
    putCategorieslist,
    deleteCategorieslist,
    AddsecondCategorieslist,
    putsecondCategorieslist,
    deletesecondCategorieslist
}